package com.ruoyi.environment.service.impl;

import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.SecurityUtils;
import com.ruoyi.environment.domain.OpmEnvParkAssess;
import com.ruoyi.environment.domain.OpmEnvParkAssess;
import com.ruoyi.environment.mapper.OpmEnvParkAssessMapper;
import com.ruoyi.environment.service.IOpmEnvParkAssessService;
import com.ruoyi.system.api.LinkFileServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 园区环评资料Service业务层处理
 *
 * @author cjie
 * @date 2021-07-23
 */
@Service
public class OpmEnvParkAssessServiceImpl extends LinkFileServiceImpl implements IOpmEnvParkAssessService {
    @Autowired
    private OpmEnvParkAssessMapper opmEnvParkAssessMapper;

    /**
     * 查询园区环评资料
     *
     * @param id 园区环评资料ID
     * @return 园区环评资料
     */
    @Override
    public OpmEnvParkAssess selectOpmEnvParkAssessById(Long id) {
        OpmEnvParkAssess result = opmEnvParkAssessMapper.selectOpmEnvParkAssessById(id);
        result.setFileList(getFileList(id.toString()));
        return result;
    }

    /**
     * 查询园区环评资料列表
     *
     * @param opmEnvParkAssess 园区环评资料
     * @return 园区环评资料
     */
    @Override
    public List<OpmEnvParkAssess> selectOpmEnvParkAssessList(OpmEnvParkAssess opmEnvParkAssess) {
        return opmEnvParkAssessMapper.selectOpmEnvParkAssessList(opmEnvParkAssess);
    }

    /**
     * 新增园区环评资料
     *
     * @param opmEnvParkAssess 园区环评资料
     * @return 结果
     */
    @Override
    public int insertOpmEnvParkAssess(OpmEnvParkAssess opmEnvParkAssess) {
        opmEnvParkAssess.setId(IdUtil.getSnowflake(0, 0).nextId());
        opmEnvParkAssess.setCreateTime(DateUtils.getNowDate());
        opmEnvParkAssess.setCreateBy(SecurityUtils.getUsername());
        linkFile(opmEnvParkAssess.getFileIdList(), opmEnvParkAssess.getId().toString());
        return opmEnvParkAssessMapper.insertOpmEnvParkAssess(opmEnvParkAssess);
    }

    /**
     * 修改园区环评资料
     *
     * @param opmEnvParkAssess 园区环评资料
     * @return 结果
     */
    @Override
    public int updateOpmEnvParkAssess(OpmEnvParkAssess opmEnvParkAssess) {
        opmEnvParkAssess.setUpdateTime(DateUtils.getNowDate());
        opmEnvParkAssess.setUpdateBy(SecurityUtils.getUsername());
        linkFile(opmEnvParkAssess.getFileIdList(),Long.toString(opmEnvParkAssess.getId()));
        return opmEnvParkAssessMapper.updateOpmEnvParkAssess(opmEnvParkAssess);
    }

    /**
     * 批量删除园区环评资料
     *
     * @param ids 需要删除的园区环评资料ID
     * @return 结果
     */
    @Override
    public int deleteOpmEnvParkAssessByIds(Long[] ids) {
        String[] res = new String[ids.length];
        for(int i=0;i<ids.length;i++){
            res[i] = String.valueOf(ids[i]);
        }
        deleteLinkFile(res);
        return opmEnvParkAssessMapper.deleteOpmEnvParkAssessByIds(ids);
    }

    /**
     * 删除园区环评资料信息
     *
     * @param id 园区环评资料ID
     * @return 结果
     */
    @Override
    public int deleteOpmEnvParkAssessById(Long id) {
        return opmEnvParkAssessMapper.deleteOpmEnvParkAssessById(id);
    }
}
